﻿import mx.utils.Delegate;

/**
 * ...
 * @author wangjun
 */

class A2.preLoader.subLoadMax 
{
	private var mc:MovieClip;
	private var ld:MovieClipLoader;
	public function subLoadMax(scope:MovieClip, mc:MovieClip, obj:Object) {
		if (scope == undefined || scope.constructor != MovieClip) {
			throw new Error ('!!! subLoad :: 无scope');
		}
		if (mc == undefined || mc.constructor != MovieClip) {
			throw new Error ('!!! subLoad :: 无容器');
		}
		this.mc = mc;
		this.ld = new MovieClipLoader();
		//
		var lis:Object = new Object();
		lis.onLoadStart = Delegate.create(this, function (mc:MovieClip) {
			Delegate.create(scope,obj.onStt)({mc:mc});
		});
		lis.onLoadProgress = Delegate.create(this, function (mc:MovieClip, ld:Number, tt:Number) {
			Delegate.create(scope,obj.onPP)({per:Math.round(ld/tt*100), cur:ld, ttl:tt, mc:mc});
		});
		lis.onLoadInit = Delegate.create(this, function (mc:MovieClip) {
			Delegate.create(scope,obj.onOK)({mc:mc,w:mc._width,h:mc._height});
		});
		this.ld.addListener(lis);
	}
	public function load(url):Void {
		trace('url -> '+url+' ctt -> '+this.mc);
		this.ld.loadClip(url, this.mc);
	}
	
}